package com.hzmg.akkacloud.common.model;

import com.google.common.collect.Maps;
import com.hzmg.akkacloud.common.AkkaCloudSerializable;

import java.util.Map;

/**
 * service instance for center
 *
 * @author zbw
 * @since 2022/8/6
 */
public class ServiceInstance implements AkkaCloudSerializable {
    // 集群所属的应用名称
    private final String appName;
    // 集群中所有机器的信息 address->work
    private final Map<String, WorkerInfo> address2WorkerInfo;

    public ServiceInstance() {
        this.appName = null;
        address2WorkerInfo = Maps.newConcurrentMap();
    }
    public ServiceInstance(String appName, Map<String, WorkerInfo> address2WorkerInfo) {
        this.appName = appName;
        this.address2WorkerInfo = address2WorkerInfo;

    }

    /**
     * 获取该集群所有的机器信息
     *
     * @return 地址: 机器信息
     */
    public Map<String, WorkerInfo> getAddress2WorkerInfo() {
        return address2WorkerInfo;
    }

    /**
     * 根据ip地址返回对应的服务
     */
    public WorkerInfo getIpForWorkers(String address) {
        return getAddress2WorkerInfo().get(address);
    }


}
